using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MonoCash
{
    public partial class AppWindow : Form
    {
        private int childFormNumber = 0;

        public AppWindow()
        {
            InitializeComponent();
            
#if DEBUG
            dataViewerToolStripMenuItem.Visible = true;
            rawTransactionDetailsTableToolStripMenuItem.Visible = true;
            rawTransactionsTableToolStripMenuItem.Visible = true;
#endif
            
            ShowNewForm("SummaryView");

        }
        private void ShowNewForm(string name)
        {
            
            try
            {
                Form f = (Form)Activator.CreateInstance(Type.GetType("MonoCash." + name));
                f.MdiParent = this;
                f.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to launch " + name + "\n" + ex.Message);
            }

        }
        private void ShowSimpleEditorForm(string tableName)
        {
            
            try
            {
                SimpleTableEditor f = new SimpleTableEditor(tableName);
                f.MdiParent = this;
                f.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to launch " + tableName + "\n" + ex.Message);
            }

        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            // Create a new instance of the child form.
            Form childForm = new Form();
            // Make it a child of this MDI form before showing it.
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
                
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
                // TODO: Add code here to save the current contents of the form to a file.
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // TODO: Use System.Windows.Forms.Clipboard to insert the selected text or images into the clipboard
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // TODO: Use System.Windows.Forms.Clipboard to insert the selected text or images into the clipboard
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // TODO: Use System.Windows.Forms.Clipboard.GetText() or System.Windows.Forms.GetData to retrieve information from the clipboard.
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowNewForm("AppSettings");
        }

        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            Program.AppSettings.Data.SaveData();
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Program.AppSettings.Data.SaveData();
        }


        private void welcomeScreenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowNewForm("SummaryView");
        }

        private void accountsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowNewForm("Accounts");
        }

        private void currenciesToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ShowSimpleEditorForm("Currencies");
        }

        private void investmentsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowSimpleEditorForm("Securities");
        }

        private void pricesToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ShowNewForm("Prices");
        }

        private void accountTypesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowSimpleEditorForm("AccountTypes");
        }

        private void accountingCategoriesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowSimpleEditorForm("AccountingCategories");
        }

        private void transactionTypesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowSimpleEditorForm("TransactionDetailTypes");
        }

        private void dataViewerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowSimpleEditorForm("Accounts");
        }

        private void rawTransactionDetailsTableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowSimpleEditorForm("TransactionDetails");
        }

        private void rawTransactionsTableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowSimpleEditorForm("Transactions");
        }

        private void balanceSheetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowNewForm("BalanceSheet");
        }

        private void incomeStatementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowNewForm("IncomeStatement");
        }


    }
}
